﻿Public Class SubeEkran
    Dim rotaSubeIDleri As List(Of Integer)
    Dim dtGelenKargolar As DataTable
    Dim dtUstMerkezMesafeler As DataTable
    Dim dtDagitimAracinaYuklenecekler As DataTable
    Dim gonderenSubeID As Integer
    Dim subeGuncellensinMi As Boolean = True
    Dim kapatilicaLogin As Boolean = False
    Dim kaydedilenKargoID As Integer

    Private Sub bt_kaydet_Click(sender As Object, e As EventArgs) Handles bt_kaydet.Click
        FaturaTutariniHesapla()
        If subeGuncellensinMi Then gonderenSubeID = cbGonderenSube.SelectedValue

        If rotaSubeIDleri Is Nothing Then
            MsgBox("Hedef Şube Seçmediniz", MsgBoxStyle.Exclamation)
            Return
        End If

        Dim adresTeslimMi = 0, adresAlimliMi As Integer = 0
        If chAdresTeslim.Checked Then adresTeslimMi = 1
        If chAdresTeslim.Checked Then adresTeslimMi = 1


        Dim eklemesorgusu As String = "INSERT INTO kargolar(gonderenTC, aliciTC, gonderenSube, aliciSube, urunTuru, faturaTuru, urunIcerik, urunBoyut, urunAgirlik, odemeTuru, ucret, adresTeslim, adresAlimli,rotasira,rotatoplam,alinmatarihi) VALUES (" &
            "'" & temizle(tbGonderenTC.Text) & "', " &
            "'" & temizle(tbAliciTC.Text) & "', " &
            "'" & temizle(gonderenSubeID) & "', " &
            "'" & temizle(cbHedefSube.SelectedValue) & "', " &
            "'" & temizle(cbKargoTuru.Text) &
            "', '" & temizle(cbFaturaTuru.Text) &
            "', '" & temizle(tbKargoIcerigi.Text) &
            "', '" & temizle(tbKoliBoyutu.Text) &
            "', '" & temizle(tbKoliAgirlik.Text) &
            "', '" & temizle(cbOdemeTuru.Text) &
            "', '" & temizle(tbFaturaTutar.Text) &
            "', '" & adresTeslimMi &
            "', " & adresAlimliMi & ", 0, " &
            rotaSubeIDleri.Count &
            ",'" & DateTime.Now & "')"

        Sorgula(eklemesorgusu)

        ' eklenen kargonun id sini bul
        Dim sonKargoGetir = Sorgula("select MAX(kargoID) as sonkargo from kargolar")
        Dim sonKargoID = sonKargoGetir.Rows(0)("sonkargo")

        ' rotayi kaydet
        Dim sirano = 1
        Dim rotaKaydetSql = "insert into kargorotalar (kargoID, sira, subeID) values "
        For Each id In rotaSubeIDleri
            rotaKaydetSql &= "(" & sonKargoID & "," & sirano & "," & id & "), "
            sirano += 1
        Next

        rotaKaydetSql = rotaKaydetSql.Substring(0, rotaKaydetSql.Length - 2)
        Sorgula(rotaKaydetSql)

        ' teslim alındı işlemini kaydet

        Dim islemOlusturSQL = "insert into kargorotaislemleri (kargoID, kaynaksubeID, hedefsubeID, islem, sira,tarih) values (" & sonKargoID & ",0," & gonderenSubeID & ",'kargo müşteriden teslim alındı', 0, '" & DateTime.Now & "')"
        Sorgula(islemOlusturSQL)
        kaydedilenKargoID = sonKargoID
        MsgBox("Kargo Başarıyla Eklendi", MsgBoxStyle.Information)
        btnFisBas.Enabled = True
    End Sub

    Private Sub SubeEkran_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If subeGuncellensinMi Then
            cbGonderenSube.DataSource = Sorgula("select * from merkezlersubeler where merkezmi = 0")
            cbGonderenSube.DisplayMember = "Adi"
            cbGonderenSube.ValueMember = "ID"
        End If

        cbHedefSube.DataSource = Sorgula("select * from merkezlersubeler where merkezmi = 0")
        cbHedefSube.DisplayMember = "Adi"
        cbHedefSube.ValueMember = "ID"

        dgvGelenKargolariGuncelle()
        dtUstMerkezMesafeler = Sorgula("select ID, ustMerkezMesafe from merkezlersubeler")


    End Sub



    Public Sub SubeSec(ByVal subeID As Integer, ByVal subeAdi As String, Optional ByVal kilitle As Boolean = False)
        subeGuncellensinMi = False
        cbGonderenSube.Text = subeAdi
        gonderenSubeID = subeID
        Me.Text = subeAdi

        If kilitle Then cbGonderenSube.Enabled = False
        If kilitle Then kapatilicaLogin = True
    End Sub

    Sub dgvGelenKargolariGuncelle()
        If subeGuncellensinMi Then gonderenSubeID = cbGonderenSube.SelectedValue
        Dim musteridenGelenKargolarSorgu = "select merkezlersubeler.Adi as sonrakiSubeAdi , kargolar.*,kargorotalar.subeID as sonrakiSubeID from kargolar " &
            " left join kargorotalar on (kargolar.kargoID = kargorotalar.kargoID and kargolar.rotasira + 1 = kargorotalar.sira) " &
            " left join merkezlersubeler on (kargorotalar.subeID = merkezlersubeler.ID) " &
            " where kargolar.kargoID in " &
            " (select kargoID from kargorotaislemleri " &
            " where hedefsubeID = " & gonderenSubeID & ") " &
            " and kargolar.rotasira = 0"

        Dim dtMusteridenGelenKargolar = Sorgula(musteridenGelenKargolarSorgu)
        dgvMusteridenGelenKargolar.DataSource = dtMusteridenGelenKargolar

        Dim merkezdenGelenIndirilmisKargolar = "select * from kargolar where rotasira = rotatoplam and teslimedildi = 0 and indirildi = 1 and dagitimda = 0 and aliciSube = " & gonderenSubeID
        Dim dtMerkezdenGelenIndirilmisKargolar = Sorgula(merkezdenGelenIndirilmisKargolar)
        dgvMerkezdenGelenKargolar.DataSource = dtMerkezdenGelenIndirilmisKargolar

        Dim merkezdenGelenIndirilmemisKargolar = "select * from kargolar where rotasira = rotatoplam and teslimedildi = 0 and indirildi = 0 and aliciSube = " & gonderenSubeID
        Dim dtMerkezdenGelenIndirilmemisKargolar = Sorgula(merkezdenGelenIndirilmemisKargolar)
        dgvMerkezdenGelenIndirilmemisKargolar.DataSource = dtMerkezdenGelenIndirilmemisKargolar

        Dim dagitimAracinaYukleneceklerSQL = "select * from kargolar where rotasira = rotatoplam and teslimedildi = 0 and indirildi = 1 and dagitimda = 0 and aliciSube = " & gonderenSubeID
        Dim dtDagitimAracinaYuklenecekler = Sorgula(dagitimAracinaYukleneceklerSQL)
        dgvDagitim.DataSource = dtDagitimAracinaYuklenecekler

        Dim dagitimAracindanGelenlerSQL = "select * from kargolar where rotasira = rotatoplam and teslimedildi = 0 and indirildi = 1 and dagitimda = 1 and aliciSube = " & gonderenSubeID
        Dim dagitimAracindanGelenler = Sorgula(dagitimAracindanGelenlerSQL)
        dgvDagitimdanDonus.DataSource = dagitimAracindanGelenler
    End Sub

    Private Sub cbHedefSube_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbHedefSube.SelectedIndexChanged
        Try
            dtUstMerkezMesafeler = Sorgula("select ID, ustMerkezMesafe from merkezlersubeler")
            Dim bolgeler As New List(Of Integer)
            Dim toplammesafe = 0
            If subeGuncellensinMi Then gonderenSubeID = cbGonderenSube.SelectedValue
            lbRota.Items.Clear()
            rotaSubeIDleri = RotaHesapla(gonderenSubeID, cbHedefSube.SelectedValue)
            For Each id In rotaSubeIDleri
                If id = 0 Then Continue For
                Dim mesafe = (From sube In dtUstMerkezMesafeler Where sube("ID") = id Select sube("ustMerkezMesafe")).FirstOrDefault()

                If IsNumeric(mesafe) Then
                    toplammesafe += mesafe
                    'lbRota.Items.Add(SubeAdiGetir(id).Trim() & " - mesafe " & mesafe & " km")
                    lbRota.Items.Add(SubeAdiGetir(id).Trim())
                Else
                    'lbRota.Items.Add(SubeAdiGetir(id).Trim() & " - BOLGE ")
                    lbRota.Items.Add(SubeAdiGetir(id).Trim())
                    bolgeler.Add(id)
                End If
            Next
            rotaSubeIDleri.RemoveAt(0)

            lbRota.Items.Add(String.Empty)
            If bolgeler.Count > 0 Then
                Dim mesafe As Double = bolgelerArasiMesafeHesapla(bolgeler(0), bolgeler(1))
                lbRota.Items.Add("Bölgeler arası mesafe: " & mesafe)
                ' toplammesafe += mesafe
            End If

            lbRota.Items.Add("Toplam Mesafe: " & toplammesafe & " km")
            lblRota.Visible = True
            lbRota.Visible = True

        Catch ex As Exception

            'MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try


    End Sub

    Private Sub llbGondericiBul_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles llbGondericiBul.LinkClicked
        cagrimTipi = "gonderici"
        Dim f As New MusteriBulEkle
        f.cagiranForm = Me
        f.ShowDialog()
    End Sub

    Private Sub tbGonderenTC_Leave(sender As Object, e As EventArgs) Handles tbGonderenTC.Leave
        Dim kisiAra = Sorgula("select * from musteriler where tc = " & tbGonderenTC.Text)
        If Not IsNothing(kisiAra) Then
            tbGonderenAd.Text = kisiAra.Rows(0)("ad")
            tbGonderenSoyad.Text = kisiAra.Rows(0)("soyad")
            tbGonderenTelefon.Text = kisiAra.Rows(0)("telefon")
            tbGonderenAdres.Text = kisiAra.Rows(0)("adres")
        End If
    End Sub

    Dim cagrimTipi As String
    Public Sub BilgileriDoldur(ByVal tc As String, ByVal ad As String, ByVal soyad As String, ByVal telefon As String, ByVal adres As String)
        If cagrimTipi = "gonderici" Then
            tbGonderenAd.Text = ad
            tbGonderenSoyad.Text = soyad
            tbGonderenTelefon.Text = telefon
            tbGonderenAdres.Text = adres
            tbGonderenTC.Text = tc
        ElseIf cagrimTipi = "alici" Then
            tbAliciAd.Text = ad
            tbAliciSoyad.Text = soyad
            tbAliciTelefon.Text = telefon
            tbAliciAdres.Text = adres
            tbAliciTC.Text = tc
        End If
    End Sub

    Private Sub llbAliciBul_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles llbAliciBul.LinkClicked
        cagrimTipi = "alici"
        Dim f As New MusteriBulEkle
        f.cagiranForm = Me
        f.ShowDialog()
    End Sub

    Private Sub tbAliciTC_Leave(sender As Object, e As EventArgs) Handles tbAliciTC.Leave
        Dim kisiAra = Sorgula("select * from musteriler where tc = " & tbAliciTC.Text)
        If Not IsNothing(kisiAra) Then
            tbAliciAd.Text = kisiAra.Rows(0)("ad")
            tbAliciSoyad.Text = kisiAra.Rows(0)("soyad")
            tbAliciTelefon.Text = kisiAra.Rows(0)("telefon")
            tbAliciAdres.Text = kisiAra.Rows(0)("adres")
        End If
    End Sub

    Private Sub bt_hesapla_Click(sender As Object, e As EventArgs) Handles bt_hesapla.Click
        FaturaTutariniHesapla()

    End Sub

    Sub FaturaTutariniHesapla()
        tbFaturaTutar.Text = CType(tbKoliAgirlik.Text, Double) * CType(tbKoliBoyutu.Text, Double)
    End Sub

    Private Sub bt_İPTAL_Click(sender As Object, e As EventArgs) Handles bt_İPTAL.Click
        tbAliciAd.Text = ""
        tbAliciAdres.Text = ""
        tbAliciSoyad.Text = ""
        tbAliciTC.Text = ""
        tbAliciTelefon.Text = ""
        tbDigerSebep.Text = ""
        tbFaturaTutar.Text = ""
        tbGonderenAd.Text = ""
        tbGonderenAdres.Text = ""
        tbGonderenSoyad.Text = ""
        tbGonderenTC.Text = ""
        tbGonderenTelefon.Text = ""
        tbKargoIcerigi.Text = ""
        tbKoliAgirlik.Text = ""
        tbKoliBoyutu.Text = ""
    End Sub

    Private Sub btnAracaYükle_Click(sender As Object, e As EventArgs) Handles btnAracaYükle.Click
        'Dim seciliSatirIdx = dgvMusteridenGelenKargolar.SelectedCells(0).RowIndex
        'Dim id = dgvMusteridenGelenKargolar.Rows(seciliSatirIdx).Cells(0).GetEditedFormattedValue(seciliSatirIdx, DataGridViewDataErrorContexts.Display)
        'MsgBox(id)

        'Dim seciliKargoGetir = Sorgula("select * from kargolar where kargoID = " & id)
        'Dim seciliKargo = seciliKargoGetir.Rows(0)

        'Dim sonrakiIslemSira = seciliKargo("rotasira")

        'Dim sonrakiRotaGetir = Sorgula("select * from kargorotalar where kargoID = " & id & " and sira = " & sonrakiIslemSira + 1)
        'Dim sonrakiRota = sonrakiRotaGetir.Rows(0)
        'Dim sonrakiMerkezID = sonrakiRota("subeID")

        'Dim sonrakiMerkezGetir = Sorgula("select * from merkezlersubeler where ID = " & sonrakiMerkezID)
        'Dim sonrakiMerkez = sonrakiMerkezGetir.Rows(0)
        'MsgBox(sonrakiMerkez("Adi"))
        If subeGuncellensinMi Then gonderenSubeID = cbGonderenSube.SelectedValue
        If dgvMusteridenGelenKargolar.SelectedCells.Count < 1 Then
            MsgBox("Bir kargo seçmelisiniz", MsgBoxStyle.Exclamation)
            Return
        End If

        Dim secilenSatirIdx = dgvMusteridenGelenKargolar.SelectedCells(0).RowIndex
        Dim kargoID = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("kargoID").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)
        '  Dim gonderenSubeID = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("gonderenSube").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)

        Dim sonrakiSubeID = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("sonrakiSubeID").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)
        Dim sonrakiSubeAdi = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("sonrakiSubeAdi").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)
        Dim rotasira = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("rotasira").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)
        Dim gonderenSube = dgvMusteridenGelenKargolar.Rows(secilenSatirIdx).Cells("gonderenSube").GetEditedFormattedValue(secilenSatirIdx, DataGridViewDataErrorContexts.Display)

        Dim sqlIslemEkle = "insert into kargorotaislemleri (kargoID, kaynaksubeID, hedefsubeID, islem, sira,tarih) values " &
            "(" & kargoID & "," & gonderenSubeID & "," & sonrakiSubeID & ",'Araca Yüklendi'," & rotasira + 1 & ", '" & DateTime.Now & "')"
        Sorgula(sqlIslemEkle)

        Dim sqlKargoGuncelle = "update kargolar set rotasira = rotasira + 1 where kargoID = " & kargoID
        Sorgula(sqlKargoGuncelle)
        dgvGelenKargolariGuncelle()

    End Sub

    Private Sub TabPage2_Enter(sender As Object, e As EventArgs) Handles TabPage2.Enter
        dgvGelenKargolariGuncelle()
    End Sub

    Private Sub btnTeslimEt_Click(sender As Object, e As EventArgs) Handles btnTeslimEt.Click
        Dim satirIdx = dgvMerkezdenGelenKargolar.SelectedCells(0).RowIndex
        Dim kargoID = dgvMerkezdenGelenKargolar.Rows(satirIdx).Cells("kargoID").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)

        Dim teslimEdildiOlarakIsaretleSQL = "update kargolar set teslimedildi = 1, teslimtarihi = '" & DateTime.Now & "' where kargoID = " & kargoID
        Sorgula(teslimEdildiOlarakIsaretleSQL)

        Dim islemOlusturSQL = "insert into kargorotaislemleri (kargoID, kaynaksubeID, hedefsubeID, islem, sira,tarih) values (" & kargoID & "," & gonderenSubeID & ",0,'Şubeden Teslim Edildi', NULL, '" & DateTime.Now & "')"
        Sorgula(islemOlusturSQL)

        MsgBox("Kargo Teslim Edildi", MsgBoxStyle.Information)
        dgvGelenKargolariGuncelle()

    End Sub

    Private Sub btnAractanIndir_Click(sender As Object, e As EventArgs) Handles btnAractanIndir.Click
        If dgvMerkezdenGelenIndirilmemisKargolar.SelectedCells.Count = 0 Then
            MsgBox("Araçtan indirmek için bir kargo seçmeliniz", MsgBoxStyle.Exclamation)
            Return
        End If

        Dim satirIdx = dgvMerkezdenGelenIndirilmemisKargolar.SelectedCells(0).RowIndex
        Dim kargoID = dgvMerkezdenGelenIndirilmemisKargolar.Rows(satirIdx).Cells("KargoID").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)
        Dim rotasira = dgvMerkezdenGelenIndirilmemisKargolar.Rows(satirIdx).Cells("rotasira").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)

        Dim oncekiYuklemeIslemiGetir = "select * from kargorotaislemleri where kargoID = " & kargoID & " and sira = " & rotasira
        Dim oncekiYuklemeIslemi = Sorgula(oncekiYuklemeIslemiGetir)
        Dim kaynaksubeID = oncekiYuklemeIslemi.Rows(0)("kaynaksubeID")
        Dim hedefsubeID = oncekiYuklemeIslemi.Rows(0)("hedefsubeID")

        Dim indirildiIslemiSQL = "INSERT INTO [dotnetKargo].[dbo].[kargorotaislemleri]" &
           "([kargoID]" &
           ",[kaynaksubeID]" &
           ",[hedefsubeID]" &
           ",[islem]" &
           ",[sira]" &
           ",[tarih])" &
        "VALUES " &
           "(" & kargoID &
           "," & kaynaksubeID &
           "," & hedefsubeID &
           ",'Araçtan İndirildi'" &
           "," & rotasira &
           ",'" & DateTime.Now & "')"

        Sorgula(indirildiIslemiSQL)

        Dim indirildiIsaretleSQL = "update kargolar set indirildi = 1 where kargoID = " & kargoID
        Sorgula(indirildiIsaretleSQL)

        MsgBox("Kargo Araçtan Başarı ile İndirildi", MsgBoxStyle.Information)

        dgvGelenKargolariGuncelle()

    End Sub

    Private Function bolgelerArasiMesafeHesapla(p1 As Integer, p2 As Integer) As Double
        Dim sorgu = "select * from merkezbolgemesafeler where " &
            "(merkez1 = " & p1 & " and merkez2 = " & p2 & ") or" &
            "(merkez2 = " & p1 & " and merkez1 = " & p2 & ")"
        Dim sonuc = Sorgula(sorgu)
        Return sonuc.Rows(0)("mesafe")

    End Function



    Private Sub btnDagitimAracinaYukle_Click(sender As Object, e As EventArgs) Handles btnDagitimAracinaYukle.Click
        If dgvDagitim.SelectedCells.Count < 1 Then
            MsgBox("Dağıtıma çıkartmak için bir ürün seçmelinisiz", MsgBoxStyle.Exclamation)
            Return
        End If

        Dim satiridx = dgvDagitim.SelectedCells(0).RowIndex
        Dim kargoID = dgvDagitim.Rows(satiridx).Cells("kargoID").GetEditedFormattedValue(satiridx, DataGridViewDataErrorContexts.Display)
        Dim rotasira = dgvDagitim.Rows(satiridx).Cells("rotasira").GetEditedFormattedValue(satiridx, DataGridViewDataErrorContexts.Display)

        MsgBox(kargoID)

        Dim dagitimaCiktiIslemiSQL = "INSERT INTO [dotnetKargo].[dbo].[kargorotaislemleri]" &
        "([kargoID]" &
        ",[kaynaksubeID]" &
        ",[hedefsubeID]" &
        ",[islem]" &
        ",[sira]" &
        ",[tarih])" &
     "VALUES " &
        "(" & kargoID &
        "," & gonderenSubeID &
        "," & gonderenSubeID &
        ",'Dağtıma Çıkarıldı'" &
        "," & rotasira &
        ",'" & DateTime.Now & "')"

        Sorgula(dagitimaCiktiIslemiSQL)

        Dim dagitimdaOlarakIsaretleSQL = "update kargolar set dagitimda = 1 where kargoID = " & kargoID
        Sorgula(dagitimdaOlarakIsaretleSQL)

        MsgBox("Kargo dağıtıma çıkarıldı", MsgBoxStyle.Exclamation)
        dgvGelenKargolariGuncelle()

    End Sub


    Private Sub cbSebepler_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbSebepler.SelectedIndexChanged
        If (cbSebepler.Text = "Diğer") Then
            tbDigerSebep.Text = "Açıklama Girin"
            tbDigerSebep.Visible = True
        Else
            tbDigerSebep.Visible = False
            tbDigerSebep.Text = ""
        End If

    End Sub

    Private Sub btnTeslimEdilemedi_Click(sender As Object, e As EventArgs) Handles btnTeslimEdilemedi.Click
        Dim aciklama = cbSebepler.Text
        If aciklama = "Diğer" Then
            aciklama = tbDigerSebep.Text
        End If

        If cbSebepler.Text = "Teslim Edilememe Sebebini Seçin" Or tbDigerSebep.Text = "Açıklama Girin" Then
            MsgBox("Bir sebep belirtmeniz gerekiyor", MsgBoxStyle.Exclamation)
            Return
        End If
        tbDigerSebep.Text = "Açıklama Girin"
        tbDigerSebep.Visible = False
        cbSebepler.Text = "Teslim Edilememe Sebebini Seçin"

        If dgvDagitimdanDonus.SelectedCells.Count < 1 Then
            MsgBox("Bir kargo seçmelisiniz.", MsgBoxStyle.Exclamation)
        End If

        ' teslim edilemedi işlemi

        Dim satirIdx = dgvDagitimdanDonus.SelectedCells(0).RowIndex
        Dim kargoID = dgvDagitimdanDonus.Rows(satirIdx).Cells("kargoID").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)
        Dim rotasira = dgvDagitimdanDonus.Rows(satirIdx).Cells("rotasira").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)

        Dim teslimedilemediSQL = "INSERT INTO [dotnetKargo].[dbo].[kargorotaislemleri]" &
        "([kargoID]" &
        ",[kaynaksubeID]" &
        ",[hedefsubeID]" &
        ",[islem]" &
        ",[sira]" &
        ",[tarih])" &
     "VALUES " &
        "(" & kargoID &
        "," & gonderenSubeID &
        "," & gonderenSubeID &
        ",'Dağtım başarısız (" & temizle(aciklama) & ")'" &
        "," & rotasira &
        ",'" & DateTime.Now & "')"

        Sorgula(teslimedilemediSQL)

        Dim subedeOlarakIsaretleSQL = "update kargolar set dagitimda = 0 where kargoID = " & kargoID
        Sorgula(subedeOlarakIsaretleSQL)


        MsgBox("Teslim edilemedi işlemi başarı ile eklendi", MsgBoxStyle.Information)
        dgvGelenKargolariGuncelle()


    End Sub

    Private Sub tbDigerSebep_MouseClick(sender As Object, e As MouseEventArgs) Handles tbDigerSebep.MouseClick
        If (tbDigerSebep.Text.Contains("Açıklama Girin")) Then tbDigerSebep.Text = ""
    End Sub

    Private Sub btnTeslimEdildi_Click(sender As Object, e As EventArgs) Handles btnTeslimEdildi.Click
        Dim satirIdx = dgvDagitimdanDonus.SelectedCells(0).RowIndex
        Dim kargoID = dgvDagitimdanDonus.Rows(satirIdx).Cells("kargoID").GetEditedFormattedValue(satirIdx, DataGridViewDataErrorContexts.Display)

        Dim teslimEdildiOlarakIsaretleSQL = "update kargolar set teslimedildi = 1, teslimtarihi = '" & DateTime.Now & "' where kargoID = " & kargoID
        Sorgula(teslimEdildiOlarakIsaretleSQL)

        Dim islemOlusturSQL = "insert into kargorotaislemleri (kargoID, kaynaksubeID, hedefsubeID, islem, sira,tarih) values (" & kargoID & "," & gonderenSubeID & ",0,'Adrese Teslim Edildi', NULL, '" & DateTime.Now & "')"
        Sorgula(islemOlusturSQL)

        MsgBox("Kargo Adrese Teslim Edildi", MsgBoxStyle.Information)
        dgvGelenKargolariGuncelle()

    End Sub

    Private Sub SubeEkran_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        If kapatilicaLogin Then
            Login.Show()
        End If

    End Sub

    Private Sub dgvDagitimdanDonus_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDagitimdanDonus.CellContentClick

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnFisBas.Click
        Dim fis As New fisalici
        fis.kargoID = kaydedilenKargoID
        fis.Show()

        fis.lblad.Text = tbAliciAd.Text
        fis.lblsoyad.Text = tbAliciSoyad.Text
        fis.lbladres.Text = tbAliciAdres.Text
        fis.lblhedefsube.Text = cbHedefSube.Text
        fis.lbltel.Text = tbAliciTelefon.Text
    End Sub
End Class